
package ro.imc.rest.client.display;

import ro.imc.rest.client.services.ServiceType;
import ro.imc.rest.shared.dto.RestLogin;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.Label;

public class OptionsForm extends Composite {

	private static OptionsFormUiBinder uiBinder =
		GWT.create(OptionsFormUiBinder.class);
	@UiField
	ToggleButton jerseyLike;
	@UiField
	ToggleButton gwtLikeServer;
	@UiField
	ToggleButton gwtLikeClient;
	@UiField
	Label strUser;

	public static ServiceType type;

	interface OptionsFormUiBinder extends UiBinder<Widget, OptionsForm> {
	}

	public OptionsForm(RestLogin user) {

		initWidget(uiBinder.createAndBindUi(this));
		strUser.setText(user.getName());
		if (type == null) {
			type = ServiceType.GWT_JERSEY;
			jerseyLike.setDown(true);
		}
		else {
			setFromType();
		};
	}

	private void setFromType() {

		switch (type) {
		case GWT_CLIENT: {
			gwtLikeClient.setDown(true);
			break;
		}
		case GWT_JERSEY: {
			jerseyLike.setDown(true);
			break;
		}
		case GWT_SERVER: {
			gwtLikeServer.setDown(true);
			break;
		}
		}

	}

	@UiHandler("gwtLikeServer")
	void onUseGWTserverClick(ClickEvent event) {

		gwtLikeServer.setDown(true);
		gwtLikeClient.setDown(false);
		jerseyLike.setDown(false);
		type = ServiceType.GWT_SERVER;

	}

	@UiHandler("gwtLikeClient")
	void onUseGWTclientClick(ClickEvent event) {

		gwtLikeServer.setDown(false);
		gwtLikeClient.setDown(true);
		jerseyLike.setDown(false);
		type = ServiceType.GWT_CLIENT;
	}

	@UiHandler("jerseyLike")
	void onUseJersetClick(ClickEvent event) {

		gwtLikeServer.setDown(false);
		gwtLikeClient.setDown(false);
		jerseyLike.setDown(true);
		type = ServiceType.GWT_JERSEY;
	}
	
	public static ServiceType getCurrentType() {
		return type;
	}

}
